package il.ac.braude.sona.gui.infogui;

import il.ac.braude.sona.constants.Resources;

import java.awt.Color;
import java.awt.Component;
import java.awt.Insets;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
/**
 * Class for showing an info row in a frame
 * 
 * @author  Ofek Ron
 * @author Avihay Avitan
 * @author Nitzan Inbar
 * @author Sasha Rozenthal
 * Laboratory in Software Engineering,Ort Braude College.</p>
 *
 */
@SuppressWarnings("serial")
public class InfoRow extends JPanel {
	/**
	 * parameter for adding more space in the GUI
	 */
	JPanel moreBorder=new JPanel();
	
	/**
	 * initialize a new row and sets the layout for this row
	 */
	public InfoRow() {
		setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
		setBorder(BorderFactory.createMatteBorder(0, 0,2, 0, Color.LIGHT_GRAY));
		moreBorder.setBorder(new EmptyBorder(new Insets(2, 0, 0, 0)));
		//setBorder(BorderFactory.createEtchedBorder());
	}
	
	/**
	 * sets info for the row with given label as left operand and value as right operand
	 * sets more space if value contains data
	 * @param label - name of the field for the row
	 * @param value - value of the field for the row
	 */
	public void setInfo(String label,String value) {
		JLabel lab=new JLabel(label+ " : ");
		lab.setFont(Resources.Futura18);
		moreBorder.add(Box.createHorizontalStrut(15));
		moreBorder.add(lab);
		moreBorder.add(Box.createHorizontalGlue());
		if (value!=null) moreBorder.add(new JLabel(value));
		moreBorder.add(Box.createHorizontalStrut(15));
		add(moreBorder);
	}
	/**
	 * sets info for an info row, with value as component 
	 * can use for adding another row
	 * @param label - name of the field
	 * @param value  - value of the field, can be another row or a jlabel...
	 */
	public void setInfo(String label,Component value) {
		JLabel lab=new JLabel(label+ " : ");
		lab.setFont(Resources.Futura18);
		moreBorder.add(Box.createHorizontalStrut(15));
		moreBorder.add(lab);
		moreBorder.add(Box.createHorizontalGlue());
		if (value!=null) moreBorder.add(value);
		moreBorder.add(Box.createHorizontalStrut(15));
		add(moreBorder);
	}
	
	
}
